package diploma.kisel.modelas.service;

import java.util.List;

import diploma.kisel.modelas.domain.Application;
import diploma.kisel.modelas.repository.ApplicationRepositoryImpl;
import diploma.kisel.modelas.repository.api.ApplicationRepository;
import diploma.kisel.modelas.service.api.ApplicationService;

public class ApplicationServiceImpl implements ApplicationService {

	private ApplicationRepository applicationRepository = new ApplicationRepositoryImpl();

	@Override
	public List<Application> findAll() {
		return applicationRepository.findAll();
	}

	@Override
	public Application findById(int id) {
		if (id >= 0)
			return applicationRepository.findById(id);
		else
			return null;
	}

	@Override
	public Application save(Application application) {
		if (application != null) {
			if (application.getId() != null)
				applicationRepository.update(application);
			else
				applicationRepository.save(application);
		}
		return null;
	}

	@Override
	public void remove(Application application) {
		if (application != null && application.getId() != null)
			applicationRepository.remove(application);

	}

	@Override
	public void remove(int id) {
		Application application = findById(id);
		remove(application);

	}

}
